/*
 * @Description: 
 * @Author: HKH
 * @Date: 2024-10-16 16:36:28
 * @LastEditors: HKH
 * @LastEditTime: 2024-10-16 16:55:32
 */


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
//服务端

public class T {
    public static void main(String[] args) throws IOException {
        //创建ServerSocket
        ServerSocket serverSocket1 =new ServerSocket(8989);
        System.out.println("服务区端口启动成功，端口为8989");
        Socket socket =serverSocket1.accept();
        System.out.println("客户端链接成功");
        InputStream is =socket.getInputStream();
        OutputStream os=socket.getOutputStream();
        byte[] bytes =new byte[1024];
        int len =is.read(bytes);
        System.out.println("服务器读取客户端数据成功");
        System.out.println("客户端发来的数据："+new String(bytes,0,len));
        os.write("Hello world,我是服务器".getBytes());  
        System.out.println("数据发送完毕");
        os.close();
        is.close();
        socket.close();
        serverSocket1.close();
    }
}